#include<iostream>
#include<vector>
using namespace std;
void merge_sort(vector<int>& a, int left, int right)
{
    if (right - left <= 0)
        return;
    int mid = left + (right - left) / 2;
    merge_sort(a, left, mid);
    merge_sort(a, mid + 1, right);
    vector<int> tmp;
    int i = left, j = mid + 1;
    while (i <= mid && j <= right)
    {
        tmp.push_back(a[i] < a[j] ? a[i++] : a[j++]);
    }
    while (i <= mid)  tmp.push_back(a[i++]);
    while (j <= right)  tmp.push_back(a[j++]);
    for (int h = left; h <= right; h++)
    {
        a[h] = tmp[h - left];
    }

}
vector<int> MySort(vector<int>& arr) {
    int len = arr.size();
    merge_sort(arr, 0, len - 1);
    return arr;
}

int main()
{
    vector<int> test = { 11,4,58,64,9,2,34,71,17,24,68,58 };
    cout << "原数组：";
    for (int x : test)
    {
        cout << x << " ";
    }
    vector<int> ab=MySort(test);
    
    cout<<endl << "排序后:";
    for (int x : ab)
    {
        cout << x << " ";
    }
    return 0;
}